package com.ywxx.dyhelper.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Switch;

import com.ywxx.dyhelper.BuildConfig;
import com.ywxx.dyhelper.R;
import com.ywxx.dyhelper.base.BaseAcitivity;
import com.ywxx.dyhelper.model.TaskConfig;
import com.ywxx.dyhelper.utils.ConstValues;
import com.ywxx.dyhelper.widget.NumberAddSubView;


/**
 * 一键识别
 */
public class RecognitionActivity extends BaseAcitivity
{

    private NumberAddSubView labNum;
    private NumberAddSubView labOperNum;
    private NumberAddSubView labFollowNum;
    private NumberAddSubView labFansNum;
    private NumberAddSubView labVlogNum;

    private Switch sw_nofollow;
    private Switch sw_del;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recognition);

        InitUI();
        DataToUI();
    }

    @Override
    protected void InitUI()
    {
        InitTitle();
        labNum = findViewById(R.id.labNum);
        labOperNum = findViewById(R.id.labOperNum);
        labFollowNum = findViewById(R.id.labFollowNum);
        labFansNum = findViewById(R.id.labFansNum);
        labVlogNum = findViewById(R.id.labVlogNum);

        sw_nofollow = findViewById(R.id.sw_nofollow);
        sw_del = findViewById(R.id.sw_del);

        labNum.setMaxValue(6000);
        labNum.setMinValue(1);
        labNum.setValue(100);

        labOperNum.setValue(4000);
        labOperNum.setMaxValue(60000);
        labOperNum.setSeekNum(500);

        labFollowNum.setValue(500);
        labFollowNum.setMaxValue(36000);
        labFollowNum.setSeekNum(100);

        labFansNum.setValue(500);
        labFansNum.setMaxValue(100000000);
        labFansNum.setSeekNum(1000);

        labVlogNum.setValue(20);
        labVlogNum.setMaxValue(36000);
        labVlogNum.setSeekNum(10);


        llStart.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view)
            {
                appconfig = new TaskConfig();
                appconfig.runtime = labNum.getValue();
                appconfig.oprtime = labOperNum.getValue();
                appconfig.follow_num = labFollowNum.getValue();
                appconfig.fans_num = labFansNum.getValue();
                appconfig.vlog_num = labVlogNum.getValue();

                appconfig.auto_follow = sw_nofollow.isChecked();//取消关注
                appconfig.auto_like = sw_del.isChecked();//拉黑
                appconfig.unit = "条";

                ConstValues.SaveValue(RecognitionActivity.this, "runtime" + TaskType, appconfig.runtime);
                ConstValues.SaveValue(RecognitionActivity.this, "opertime" + TaskType, appconfig.oprtime);
                ConstValues.SaveValue(RecognitionActivity.this, "follow_num" + TaskType, appconfig.follow_num);
                ConstValues.SaveValue(RecognitionActivity.this, "fans_num" + TaskType, appconfig.fans_num);
                ConstValues.SaveValue(RecognitionActivity.this, "vlog_num" + TaskType, appconfig.vlog_num);
                ConstValues.SaveValue(RecognitionActivity.this, "nofollow" + TaskType, appconfig.auto_follow);
                ConstValues.SaveValue(RecognitionActivity.this, "delfan" + TaskType, appconfig.auto_like);

                StartTaskServer(TaskType);
            }
        });

    }

    @Override
    protected void DataToUI()
    {
        int runtime = ConstValues.getIntValue(this, "runtime" + TaskType, 100);
        int opertime = ConstValues.getIntValue(this, "opertime" + TaskType, 4000);
        int follow = ConstValues.getIntValue(this, "follow_num" + TaskType, 5000);
        int fans = ConstValues.getIntValue(this, "fans_num" + TaskType, 10000);
        int vlog = ConstValues.getIntValue(this, "vlog_num" + TaskType, 20);
        boolean nofollow = ConstValues.getBooleanValue(this, "nofollow" + TaskType, false);
        boolean delfan = ConstValues.getBooleanValue(this, "delfan" + TaskType, false);

        labNum.setValue(runtime);
        labOperNum.setValue(opertime);
        labFollowNum.setValue(follow);
        labFansNum.setValue(fans);
        labVlogNum.setValue(vlog);

        sw_nofollow.setChecked(nofollow);
        sw_del.setChecked(delfan);

    }
}